package com.devshephard.juchm.createThread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class CreateThread {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //创建线程1
        BaseThread thread1 = new BaseThread();
        thread1.start();

        Thread.getAllStackTraces();

        //创建线程2
        RunableThread runableThread = new RunableThread();
        Thread thread2 = new Thread(runableThread);
        thread2.start();


        //创建线程3
        FutureTask<String> task = new FutureTask<>(new Callable<String>() {
            @Override
            public String call() throws Exception {
                return "FutureTask创建线程";
            }
        });
        Thread thread3 = new Thread(task);
        thread3.start();

        System.out.println(task.get());


        //简略版
        new Thread(()->{
            System.out.println("简略创建线程");
        }).start();


    }

}

class BaseThread extends Thread{
    @Override
    public void run() {
        System.out.println("普通Thread创建线程");
    }
}

class RunableThread implements Runnable{
    @Override
    public void run() {
        System.out.println("Runable创建线程");
    }
}